import 'package:equatable/equatable.dart';
import 'package:backend.purchases/infrastructure/dtos/yookassa_api/payments/succeeded_payment/yookassa_api_bank_card_info_dto.dart';

const kYookassaApiSucceededPaymentMethodIdKey = 'id';
const kYookassaApiSucceededPaymentMethodSavedKey = 'saved';
const kYookassaApiSucceededPaymentMethodBankCardInfoKey = 'card';

class YookassaApiSucceededPaymentMethodDto extends Equatable {
  const YookassaApiSucceededPaymentMethodDto._internal({
    required this.id,
    required this.saved,
    required this.bankCardInfoDto,
  });

  final String id;
  final bool saved;
  final YookassaApiBankCardInfoDto bankCardInfoDto;

  @override
  List<Object?> get props {
    return [
      id,
      saved,
      bankCardInfoDto,
    ];
  }

  factory YookassaApiSucceededPaymentMethodDto.fromJson(Map<String, dynamic> json) {
    final id = json[kYookassaApiSucceededPaymentMethodIdKey];

    final saved = json[kYookassaApiSucceededPaymentMethodSavedKey];

    final bankCardInfoJson = json[kYookassaApiSucceededPaymentMethodBankCardInfoKey];
    final bankCardInfoDto = YookassaApiBankCardInfoDto.fromJson(bankCardInfoJson);

    return YookassaApiSucceededPaymentMethodDto._internal(
      id: id,
      saved: saved,
      bankCardInfoDto: bankCardInfoDto,
    );
  }
}
